package com.alibaba.service;

import com.alibaba.bean.PostComment;
import com.alibaba.bean.PostCommentResult;
import com.alibaba.mapper.PostCommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PostCommentService {

    @Autowired
    private PostCommentMapper postCommentMapper;

    public PostCommentResult reply(PostComment postComment) {
        PostCommentResult pcr = new PostCommentResult();
        PostComment pc = new PostComment();
        pcr.setResult(false);
        try{
            int i = postCommentMapper.num();
            postCommentMapper.PostComment(postComment);
            postCommentMapper.commentInc(postComment.getDailyId());
            if (postCommentMapper.num() > i ) {
                pcr.setErrorMsg("评论成功");
                pcr.setResult(true);
            } else {
                pcr.setErrorMsg("评论失败");
            }
        } catch (Exception e) {
            pcr.setErrorMsg(e.getMessage());
            e.printStackTrace();
        }
        return pcr;
    }

}
